//
//  LFHTTPManager.swift
//  SDAutoWeibo
//
//  Created by 刘健 on 16/3/23.
//  Copyright © 2016年 Clemmie. All rights reserved.
//

import UIKit
import AFNetworking

//封装 第三方，便利维护
class LFHTTPManager: NSObject {
    
   static let sharedManager = LFHTTPManager()
    
   private var afnSharedManager: AFHTTPSessionManager
    
   private override init() {
    
    afnSharedManager = AFHTTPSessionManager(baseURL: baseURL)
    
    afnSharedManager.responseSerializer.acceptableContentTypes?.insert("text/plain")
    
    }
    
    /**
     网络请求GET
     */
    func GETData(URLString: String,parameters: AnyObject?,success:(result:[String : AnyObject]?, error: NSError?) -> ()) {
        afnSharedManager.GET(URLString, parameters: parameters, progress: nil, success: { (_, result) -> Void in
            
            let dict = result as? [String : AnyObject]
            success(result: dict, error: nil)
            
            }) { (_ , error) -> Void in
                
            success(result: nil, error: error)
        }
    }
    
    /**
    *  网络请求POST
    */
    func POSTData(URLString: String,parameters: AnyObject?,success:(result:[String : AnyObject]?, error: NSError?) ->()) {
        afnSharedManager.POST(URLString, parameters: parameters, progress: nil, success: { (_ , result) -> Void in
            let dict = result as? [String : AnyObject]
            success(result: dict, error: nil)
            }) { (_ , error) -> Void in
                success(result: nil, error: error)
        }
        
    }
}
